#pragma once

// ChatClient command target

class ChatClient : public CAsyncSocket
{
public:
	ChatClient();

	void init()
	{
		memset(this,0,sizeof(this));
	}

	ChatClient(std::string &ip,int port);
	static ChatClient* Instance(std::string ip="127.0.0.1",int port=8888);
    static UINT ProcessResult(LPVOID p); 
	BOOL ConnectServer();
	BOOL Login(const char *user,const char *uid,int scene_id,int league_id,int lock,const char* type);
	BOOL Logout(const char* user,const char* type);
	BOOL System(const char* type,const char* user,int team_id,const char *user_list[],const char* message,const char * t);
	BOOL GetAllMapUsers(const char*type);
	BOOL Heart();
	BOOL ChangeMap(const char* from,const char * to,const char* type);
	BOOL GetUsers();
	BOOL FriendStatu(int scene_id,const char* type);
	BOOL GetUserInfo(const char *user);
	BOOL ChatMap(int scene_id,const char * message,const char* type);
	BOOL ChatWorld(const char * message,const char* type);
	BOOL ChatFriend(const char* user,const char* message,const char* type);
	BOOL ChatPrivate(const char* user,const char*message,const char * type);
    BOOL CreateTeam(const char* team_id,const char* type);
    BOOL DestroyTeam(const char* team_id,const char* type);
	BOOL JoinTeam(const char* team_id,const char* type);
	BOOL QuitTeam(const char* team_id,const char* type);
	BOOL ChatTeam(const char* team_id,const char* message,const char* type);
	BOOL ChatLeague(const char* message,const char * type);
	BOOL AddBlackList(const char* user);
	BOOL RemoveBlackList(const char* user);
	BOOL KickUser(const char* user);					    
	void SendPolicyRequest();
	std::string GetQueueContent();
	virtual ~ChatClient();
protected:
	void OnConnect(int errCode);
	void OnReceive(int errCode);
	void OnSend(int errCode);
	BOOL ChatCommon(const char * format,...);
	BOOL SendToServer( const char *str,BOOL front=FALSE);
private:
	enum{BUFF_LEN=2048};
    char m_buffer[BUFF_LEN];
	std::deque<char*> m_deque;
	std::deque<char*> m_send_queue;
	BOOL m_policy_send_ok;
	std::string m_ip;
	UINT    m_port;
	static ChatClient* s_client;

};


